NAs for agb_growth - plots 13,14 and 15 miss data (?)
Code
merged <- merged %>%group_by(subplot) %>%mutate(fitted_GAM5 =predict(gam(agb_growth ~s(Year, k =5), data =cur_data()),newdata =cur_data() ) ) %>%ungroup()merged <- merged %>%group_by(subplot) %>%mutate(fitted_GAM8 =predict(gam(agb_growth ~s(Year, k =8), data =cur_data()),newdata =cur_data() ) )%>%ungroup()merged <- merged %>%group_by(subplot) %>%mutate(fitted_GAM_flexibleK =predict(gam(agb_growth ~s(Year, k =-1), data =cur_data()), #allows model to choose the best k for each subplotnewdata =cur_data() ) )%>%ungroup()p1=ggplot(merged, aes(x = Year, y = fitted_GAM5, color = subplot)) +geom_line(size =1) +# predicted trajectorygeom_point(data = merged, aes(x = Year, y = agb_growth, color = subplot),inherit.aes =FALSE, size =2) +# observed pointstheme_bw() +labs(x ="Year", y ="agb_growth", title="GAM-k=5") +theme(legend.position ="none")plot(merged$agb_growth, merged$fitted_GAM5)
ggplot(merged, aes(mean_z_tmax, agb_growth - fitted_GAM_flexibleK)) +geom_point() +geom_smooth(method ="lm", color ="red", se =FALSE) +facet_wrap(~ Treatment, scales ="free_y")+ggtitle("GAM8 residuals vs Tmax")
GAM bs = “fs”
Code
#test GAM that is done on the full models (bs = "fs")merged <- merged %>%mutate(fitted_GAM8_fs =predict(gam(agb_growth ~s(Year, subplot, bs ="fs", k =8), data =cur_data()),newdata =cur_data() ) )
Code
p111=ggplot(merged, aes(x = Year, y = fitted_GAM8_fs, color = subplot)) +geom_line(size =1) +# predicted trajectorygeom_point(data = merged, aes(x = Year, y = agb_growth, color = subplot),inherit.aes =FALSE, size =2) +# observed pointstheme_bw() +facet_wrap(~ subplot, scales ="free_y")+labs(x ="Year", y ="agb_growth", title="GAM-k=8 fs") +theme(legend.position ="none")p111
ggplot(merged, aes(mean_z_tmax, agb_growth - fitted_GAM8_fs)) +geom_point() +geom_smooth(method ="lm", color ="red", se =FALSE) +facet_wrap(~ Treatment, scales ="free_y")+ggtitle("GAM5 residuals vs Tmax")
Code
#GAM captures early and late patterns faithfully, best edges behaviour. more variance on early years not linked to the model
slider
complete=TRUE (reject incomplete windows, NA at the beggining and the end), window per observation, not true “moving time windows”, window is just row-based.